package com.burstly.lib.component.networkcomponent.burstly.html.rewards;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.Looper;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.webkit.JavascriptInterface;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout.LayoutParams;
import android.widget.MediaController;
import android.widget.VideoView;
import com.burstly.lib.component.networkcomponent.burstly.OverlayContainer;
import com.burstly.lib.component.networkcomponent.burstly.html.CloseableContainer;
import com.burstly.lib.component.networkcomponent.burstly.html.ICloseControl;
import com.burstly.lib.component.networkcomponent.burstly.html.IDestroyableActivityLifecycleAware;
import com.burstly.lib.component.networkcomponent.burstly.html.IJsBridge;
import com.burstly.lib.component.networkcomponent.burstly.html.LoadingAwareWebView;
import com.burstly.lib.component.networkcomponent.burstly.html.VideoViewPane;
import com.burstly.lib.component.networkcomponent.burstly.html.mraid.MraidView;
import com.burstly.lib.component.networkcomponent.burstly.video.VideoCache;
import com.burstly.lib.component.networkcomponent.burstly.video.VideoCache.IVideoCacheListener;
import com.burstly.lib.component.networkcomponent.burstly.wrapper.ChromeClientWrapper;
import com.burstly.lib.component.networkcomponent.burstly.wrapper.WebViewClientWrapper;
import com.burstly.lib.constants.Constants;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.SafeRunnable;
import com.burstly.lib.util.Utils;
import java.util.List;

@SuppressLint({"DefaultLocale"})
public class RewardsView extends LoadingAwareWebView
  implements IDestroyableActivityLifecycleAware, View.OnClickListener, RewardsVideoView.IVideoEvents, IJsBridge, VideoCache.IVideoCacheListener, MediaPlayer.OnPreparedListener, MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener
{
  static final String BRIDGE_LOADED = "console.log(\"firing window.burstlyBridgeLoaded if defined\"); if (window.burstlyBridgeLoaded != null) window.burstlyBridgeLoaded();";
  static final LoggerExt LOG = LoggerExt.getInstance();
  private static final String NO_VIDEO_URL = "none";
  private static final String PLAY = "pVideo";
  private static final String SPLITTER = "=\"";
  static final String TAG = "RewardsView";
  public static final String VERSION = "2";
  ICloseControl mCloseButtonControl;
  ViewGroup mContentParent;
  private volatile int mDuration;
  ModalBrowserView mModalView;
  CloseableContainer<MraidView> mMraidViewContainer;
  volatile boolean mPageLoaded;
  private RewardsView mParentRewardsView;
  volatile boolean mPublishedBridgeLoaded;
  private RewardsBridgeState mState = RewardsBridgeState.LOADING;
  private volatile boolean mStopped;
  private final Handler mUiHandler = new Handler(Looper.getMainLooper());
  private VideoCache mVideoCache;
  private VideoViewPane mVideoLayout;
  RewardsVideoView mVideoView;
  CloseableContainer<RewardsVideoView> mVideoViewContainer;
  private CloseableContainer<VideoViewPane> mVideoViewPaneContainer;

  public RewardsView(Context paramContext)
  {
    super(paramContext);
    addJavascriptInterface(this, "burstlyBridge");
    setWebViewClient(new WebViewClient());
    setWebChromeClient(new WebChromeClient());
    setScrollContainer(false);
    setVerticalScrollBarEnabled(false);
    setHorizontalScrollBarEnabled(false);
    this.mContentParent = ((ViewGroup)((Activity)paramContext).getWindow().getDecorView());
  }

  private void destroyInner()
  {
    if (wasDestroyed())
      return;
    fireBridgeStateEvent(RewardsBridgeState.HIDDEN, true);
    destroyVideoView();
    stopLoading();
    if (this.mVideoCache != null)
    {
      this.mVideoCache.setCacheListener(null);
      this.mVideoCache = null;
    }
    this.mContentParent = null;
  }

  private void fireEvent(String paramString1, String paramString2, boolean paramBoolean1, boolean paramBoolean2, Object[] paramArrayOfObject)
  {
    StringBuilder localStringBuilder;
    if (this.mPageLoaded)
    {
      localStringBuilder = new StringBuilder("if (typeof burstlyRewardsBridge != \"undefined\")");
      localStringBuilder.append(paramString1);
      localStringBuilder.append(paramString2);
      localStringBuilder.append("'");
      if ((paramArrayOfObject != null) && (paramArrayOfObject.length > 0))
      {
        int i = paramArrayOfObject.length;
        for (int j = 0; j < i; j++)
        {
          Object localObject = paramArrayOfObject[j];
          localStringBuilder.append(",");
          if (paramBoolean1)
            localStringBuilder.append("'");
          localStringBuilder.append(localObject);
          if (paramBoolean1)
            localStringBuilder.append("'");
        }
      }
      localStringBuilder.append(");");
      if (paramBoolean2)
        super.loadUrl("javascript:" + localStringBuilder.toString());
    }
    else
    {
      return;
    }
    executeScriptUnSafe(localStringBuilder.toString());
  }

  static RewardsBridgeState getState(boolean paramBoolean)
  {
    if (paramBoolean)
      return RewardsBridgeState.DEFAULT;
    return RewardsBridgeState.HIDDEN;
  }

  private String getVideoUrl(String paramString)
  {
    String[] arrayOfString = paramString.split("=\"");
    try
    {
      if ((arrayOfString.length >= 2) && (arrayOfString[1].length() == 0));
      String str = arrayOfString[1].substring(0, -1 + arrayOfString[1].length());
      return str;
    }
    catch (Exception localException)
    {
    }
    return null;
  }

  private static boolean isIntentAvailable(Context paramContext, String paramString)
  {
    if (paramString == null);
    while (paramContext.getPackageManager().queryIntentActivities(new Intent(paramString), 65536).size() <= 0)
      return false;
    return true;
  }

  private void showVideoView()
  {
    int i = Utils.getFillparentValue();
    this.mContentParent.addView(this.mVideoViewPaneContainer, new FrameLayout.LayoutParams(i, i, 17));
  }

  static void sleep()
  {
    try
    {
      Thread.sleep(1000L);
      return;
    }
    catch (InterruptedException localInterruptedException)
    {
    }
  }

  private static boolean supportReverseLayout()
  {
    return Build.VERSION.SDK_INT >= 9;
  }

  @JavascriptInterface
  public boolean canOpenUrl(String paramString)
  {
    LOG.logDebug("RewardsView", "Executing 'canOpenUrl' {0}", new Object[] { paramString });
    return isIntentAvailable(getContext(), paramString);
  }

  public void closeActivity()
  {
    closeWindow();
  }

  @JavascriptInterface
  public void closeModalBrowser()
  {
    this.mUiHandler.post(new SafeRunnable(this)
    {
      public void doRun()
      {
        RewardsView.LOG.logDebug("RewardsView", "Executing 'closeModalBrowser'", new Object[0]);
        RewardsView.this.doCloseModalBrowser();
      }
    });
  }

  @JavascriptInterface
  public void closeMraid()
  {
    this.mUiHandler.post(new SafeRunnable(this)
    {
      public void doRun()
      {
        RewardsView.LOG.logDebug("RewardsView", "Executing 'closeMraid'", new Object[0]);
        RewardsView.this.doCloseMraidContainer();
      }
    });
  }

  public void closePlayer()
  {
    this.mUiHandler.post(new SafeRunnable(this)
    {
      public void doRun()
      {
        RewardsView.LOG.logDebug("RewardsView", "Executing 'closePlayer'", new Object[0]);
        RewardsView.this.doCloseVideoPlayer();
      }
    });
  }

  @JavascriptInterface
  public void closeWindow()
  {
    final OverlayContainer localOverlayContainer = getHostingOverlay();
    if (localOverlayContainer == null)
    {
      LOG.logDebug("RewardsView", "Failed to execute 'Close Window' due the view is not opened as an interstitial", new Object[0]);
      return;
    }
    this.mUiHandler.post(new SafeRunnable(this)
    {
      public void doRun()
      {
        RewardsView.LOG.logDebug("RewardsView", "Executing 'closeWindow'", new Object[0]);
        localOverlayContainer.hideOverlayed();
      }
    });
  }

  @JavascriptInterface
  public int currentTime()
  {
    LOG.logDebug("RewardsView", "Executing 'currentTime'", new Object[0]);
    if (this.mVideoView == null)
      return -1;
    return this.mVideoView.getVideoView().getCurrentPosition();
  }

  public void destroy()
  {
    destroyInner();
    super.destroy();
  }

  public void destroyVideoView()
  {
    this.mStopped = true;
    hideVideoView();
    if (this.mVideoLayout != null)
      this.mVideoLayout.destroy();
    this.mVideoLayout = null;
  }

  void dispatchAction(String paramString)
  {
    if (paramString.startsWith("pVideo"))
    {
      String str = getVideoUrl(paramString);
      if (str != null)
      {
        this.mVideoViewPaneContainer = new CloseableContainer(getContext());
        this.mVideoLayout = new VideoViewPane(getContext());
        this.mVideoViewPaneContainer.putIntoContainer(this.mVideoLayout);
        this.mVideoViewPaneContainer.setCloseClickListener(this);
        this.mVideoViewPaneContainer.setShowCloseButtonDelay(3000L);
        this.mVideoLayout.setListeners(this, this, this);
        showVideoView();
        this.mVideoLayout.playVideo(str);
      }
    }
  }

  void doCloseModalBrowser()
  {
    if (this.mModalView != null)
    {
      this.mContentParent.removeView(this.mModalView);
      this.mModalView.setCloseListener(null);
      try
      {
        this.mModalView.destroy();
        this.mModalView = null;
        fireCommonEvent("browserClosed", new Object[0]);
        return;
      }
      catch (Exception localException)
      {
        while (true)
          LOG.logDebug("RewardsView", "Problem with destroy modal view.", new Object[0]);
      }
    }
    if (this.mParentRewardsView != null)
    {
      this.mParentRewardsView.doCloseModalBrowser();
      return;
    }
    fireCommonEvent("browserWasNotOpened", new Object[0]);
  }

  void doCloseMraidContainer()
  {
    if (this.mMraidViewContainer != null)
    {
      ((MraidView)this.mMraidViewContainer.getContainedView()).onDestroy(null);
      this.mContentParent.removeView(this.mMraidViewContainer);
      this.mMraidViewContainer = null;
      fireCommonEvent("mraidContainerClosed", new Object[0]);
      return;
    }
    fireCommonEvent("mraidContainerWasNotOpened", new Object[0]);
  }

  void doCloseVideoPlayer()
  {
    if (this.mVideoViewContainer != null)
    {
      this.mContentParent.removeView(this.mVideoViewContainer);
      this.mVideoView.destroy();
      this.mVideoView = null;
      fireCommonEvent("videoClosed", new Object[0]);
      return;
    }
    fireVideoEvent("videoNotLoaded", new Object[0]);
  }

  public void downloadFailed(String paramString)
  {
    LOG.logDebug("RewardsView", "Failed to cache {0}.", new Object[] { paramString });
    fireVideoEvent("precachedFailed", new Object[0]);
  }

  public void downloadFinished(String paramString)
  {
    LOG.logDebug("RewardsView", "Finished caching of {0}.", new Object[] { paramString });
    fireVideoEvent("precached", new Object[0]);
  }

  public void downloadStarted(String paramString)
  {
    LOG.logDebug("RewardsView", "Started caching of {0}...", new Object[] { paramString });
  }

  @JavascriptInterface
  public int duration()
  {
    LOG.logDebug("RewardsView", "Executing 'duration'", new Object[0]);
    if (this.mVideoView == null)
      return -1;
    return this.mVideoView.getVideoView().getDuration();
  }

  public void ended()
  {
    fireVideoEvent("ended", new Object[0]);
  }

  public void error()
  {
    fireVideoEvent("couldNotPlayVideo", new Object[0]);
  }

  void executeScriptUnSafe(String paramString)
  {
    loadUrl("javascript:" + paramString);
  }

  void fireBridgeStateEvent(RewardsBridgeState paramRewardsBridgeState, boolean paramBoolean)
  {
    if ((this.mPageLoaded) && (this.mState != paramRewardsBridgeState))
    {
      this.mState = paramRewardsBridgeState;
      fireEvent("burstlyRewardsBridge.fireCommonEvent('", "stateChanged", false, false, new Object[] { "{bridgeState: \"" + this.mState.name().toLowerCase() + "\"}" });
    }
  }

  void fireCommonEvent(String paramString, Object[] paramArrayOfObject)
  {
    fireEvent("burstlyRewardsBridge.fireCommonEvent('", paramString, true, false, paramArrayOfObject);
  }

  void fireVideoEvent(String paramString, Object[] paramArrayOfObject)
  {
    fireEvent("burstlyRewardsBridge.fireVideoEvent('", paramString, true, false, paramArrayOfObject);
  }

  public RewardsView getParentRewardsView()
  {
    return this.mParentRewardsView;
  }

  public void getSdkVersion()
  {
    executeScriptUnSafe("if (window.burstlySdkVersion != null) window.burstlySdkVersion('" + Constants.SDK_VERSION + "')");
  }

  @JavascriptInterface
  public void hideNativeControls()
  {
    final ICloseControl localICloseControl = this.mCloseButtonControl;
    if (localICloseControl != null)
    {
      this.mUiHandler.post(new SafeRunnable(this)
      {
        public void doRun()
        {
          RewardsView.LOG.logDebug("RewardsView", "Executing 'hideNativeControls'", new Object[0]);
          localICloseControl.showClose(false);
        }
      });
      return;
    }
    LOG.logWarning("RewardsView", "Can not send 'hide native control' event. Native control listener is null", new Object[0]);
  }

  @JavascriptInterface
  public void hideVideoControls()
  {
    final RewardsVideoView localRewardsVideoView = this.mVideoView;
    if (localRewardsVideoView != null)
      this.mUiHandler.post(new SafeRunnable(this)
      {
        public void doRun()
        {
          RewardsView.LOG.logDebug("RewardsView", "Executing 'hideVideoControls'", new Object[0]);
          localRewardsVideoView.getController().setVisibility(8);
        }
      });
  }

  void hideVideoView()
  {
    if ((this.mContentParent != null) && (this.mVideoViewPaneContainer != null))
      this.mContentParent.removeView(this.mVideoViewPaneContainer);
  }

  @JavascriptInterface
  public boolean isPlaying()
  {
    return (this.mVideoLayout != null) && (this.mVideoLayout.getVideoView().isPlaying());
  }

  protected void onAttachedToWindow()
  {
    super.onAttachedToWindow();
    publishBridgeLoaded();
    fireBridgeStateEvent(getState(isShown()), false);
  }

  public void onClick(View paramView)
  {
    if (this.mModalView == paramView)
      doCloseModalBrowser();
    do
    {
      return;
      if ((this.mMraidViewContainer != null) && (this.mContentParent != null))
      {
        doCloseMraidContainer();
        return;
      }
      if (this.mVideoViewPaneContainer != null)
      {
        hideVideoView();
        return;
      }
    }
    while (this.mVideoViewContainer == null);
    doCloseVideoPlayer();
  }

  public void onCompletion(MediaPlayer paramMediaPlayer)
  {
    if (this.mDuration == 0);
    for (int i = 1000; ; i = this.mDuration)
    {
      updateDataObject(i, i);
      loadUrl("javascript:burstly_dispatchTimeupdate();");
      loadUrl("javascript:burstly_dispatchEnded();");
      this.mStopped = true;
      destroyVideoView();
      return;
    }
  }

  public void onDestroy(Activity paramActivity)
  {
    destroyInner();
    super.onDestroy(paramActivity);
  }

  protected void onDetachedFromWindow()
  {
    super.onDetachedFromWindow();
    fireBridgeStateEvent(RewardsBridgeState.HIDDEN, false);
  }

  public boolean onError(MediaPlayer paramMediaPlayer, int paramInt1, int paramInt2)
  {
    return false;
  }

  public boolean onKey(Activity paramActivity, int paramInt, KeyEvent paramKeyEvent)
  {
    return false;
  }

  @TargetApi(11)
  public void onPause(Activity paramActivity)
  {
    if (Build.VERSION.SDK_INT > 10)
    {
      onPause();
      if (this.mModalView != null)
        this.mModalView.getRewardsView().onPause();
    }
    if (Build.VERSION.SDK_INT >= 8)
    {
      if (this.mVideoView != null)
        this.mVideoView.getVideoView().suspend();
      if (this.mVideoLayout != null)
        this.mVideoLayout.getVideoView().suspend();
    }
    fireCommonEvent("backgrounded", new Object[0]);
  }

  public void onPrepared(MediaPlayer paramMediaPlayer)
  {
    this.mVideoLayout.hideProgress();
    this.mStopped = false;
    new Thread(new Runnable()
    {
      public void run()
      {
        Utils.lowerCurrentThreadPriority();
        RewardsView.access$002(RewardsView.this, RewardsView.this.mVideoLayout.getVideoView().getDuration());
        RewardsView localRewardsView = RewardsView.this;
        int i;
        if (RewardsView.this.mDuration == 0)
        {
          i = 1000;
          RewardsView.access$002(localRewardsView, i);
          RewardsView.this.updateDataObject(RewardsView.this.mDuration, 0);
          RewardsView.this.loadUrl("javascript:burstly_dispatchPlay();");
          if (!RewardsView.this.mStopped)
            if (RewardsView.this.mVideoLayout == null)
              break label122;
        }
        label122: for (VideoView localVideoView = RewardsView.this.mVideoLayout.getVideoView(); ; localVideoView = null)
        {
          if (localVideoView != null)
            break label128;
          return;
          i = RewardsView.this.mDuration;
          break;
        }
        label128: int j = localVideoView.getCurrentPosition();
        if (j < RewardsView.this.mDuration)
        {
          RewardsView.this.updateDataObject(RewardsView.this.mDuration, j);
          RewardsView.this.loadUrl("javascript:burstly_dispatchTimeupdate();");
        }
        while (true)
        {
          RewardsView.sleep();
          break;
          RewardsView.access$202(RewardsView.this, true);
        }
      }
    }).start();
  }

  @TargetApi(11)
  public void onResume(Activity paramActivity)
  {
    if (Build.VERSION.SDK_INT > 10)
    {
      onResume();
      if (this.mModalView != null)
        this.mModalView.getRewardsView().onResume();
    }
    if (Build.VERSION.SDK_INT >= 8)
    {
      if (this.mVideoView != null)
        this.mVideoView.getVideoView().resume();
      if (this.mVideoLayout != null)
        this.mVideoLayout.getVideoView().resume();
    }
    fireCommonEvent("foregrounded", new Object[0]);
  }

  protected void onVisibilityChanged(View paramView, int paramInt)
  {
    super.onVisibilityChanged(paramView, paramInt);
    publishBridgeLoaded();
    if (paramInt == 0);
    for (boolean bool = true; ; bool = false)
    {
      fireBridgeStateEvent(getState(bool), false);
      return;
    }
  }

  public void openExternalURL(String paramString)
  {
    openUrlExternal(paramString);
  }

  @JavascriptInterface
  public void openMraid(final String paramString)
  {
    this.mUiHandler.post(new SafeRunnable(this)
    {
      public void doRun()
      {
        LoggerExt localLoggerExt = RewardsView.LOG;
        Object[] arrayOfObject = new Object[1];
        arrayOfObject[0] = paramString;
        localLoggerExt.logDebug("RewardsView", "Executing 'openMraid' {0}", arrayOfObject);
        if ((paramString != null) && (RewardsView.this.mContentParent != null) && (RewardsView.this.mModalView == null) && (RewardsView.this.mVideoView == null) && (RewardsView.this.mMraidViewContainer == null))
        {
          RewardsView.this.mMraidViewContainer = new CloseableContainer(RewardsView.this.getContext());
          MraidView localMraidView = new MraidView(RewardsView.this.getContext());
          localMraidView.setInterstitial(true);
          localMraidView.loadDataWithBaseURL(null, paramString, null, "utf8", null);
          RewardsView.this.mMraidViewContainer.putIntoContainer(localMraidView);
          RewardsView.this.mMraidViewContainer.setCloseClickListener(RewardsView.this);
          int i = Utils.getFillparentValue();
          RewardsView.this.mMraidViewContainer.setLayoutParams(new FrameLayout.LayoutParams(i, i));
          RewardsView.this.mContentParent.addView(RewardsView.this.mMraidViewContainer);
          RewardsView.this.fireCommonEvent("mraidContainerOpened", new Object[0]);
          return;
        }
        RewardsView.this.fireCommonEvent("mraidContainerCouldNotBeOpened", new Object[0]);
      }
    });
  }

  @JavascriptInterface
  public void openUrlExternal(final String paramString)
  {
    this.mUiHandler.post(new SafeRunnable(this)
    {
      public void doRun()
      {
        LoggerExt localLoggerExt = RewardsView.LOG;
        Object[] arrayOfObject = new Object[1];
        arrayOfObject[0] = paramString;
        localLoggerExt.logDebug("RewardsView", "Executing 'openUrlExternal' {0}", arrayOfObject);
        if (paramString != null);
        try
        {
          Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse(paramString));
          RewardsView.this.getContext().startActivity(localIntent);
          return;
        }
        catch (Exception localException)
        {
          RewardsView.LOG.logError("RewardsView", localException.getMessage(), new Object[0]);
          RewardsView.this.fireCommonEvent("externalUrlCouldNotBeOpened", new Object[0]);
        }
      }
    });
  }

  @JavascriptInterface
  public void openUrlModal(final String paramString, final boolean paramBoolean)
  {
    this.mUiHandler.post(new SafeRunnable(this)
    {
      public void doRun()
      {
        LoggerExt localLoggerExt = RewardsView.LOG;
        Object[] arrayOfObject = new Object[1];
        arrayOfObject[0] = paramString;
        localLoggerExt.logDebug("RewardsView", "Executing 'openUrlModal' {0}", arrayOfObject);
        if ((paramString != null) && (RewardsView.this.mContentParent != null) && (RewardsView.this.mModalView == null) && (RewardsView.this.mVideoView == null) && (RewardsView.this.mMraidViewContainer == null))
        {
          RewardsView.this.mModalView = new ModalBrowserView(RewardsView.this.getContext(), paramString, paramBoolean);
          RewardsView.this.mModalView.setCloseListener(RewardsView.this);
          RewardsView.this.mModalView.getRewardsView().setHostingOverlay(RewardsView.this.getHostingOverlay());
          RewardsView.this.mModalView.getRewardsView().setParentRewardsView(RewardsView.this);
          int i = Utils.getFillparentValue();
          RewardsView.this.mModalView.setLayoutParams(new FrameLayout.LayoutParams(i, i));
          RewardsView.this.mContentParent.addView(RewardsView.this.mModalView);
          RewardsView.this.fireCommonEvent("browserOpened", new Object[0]);
          return;
        }
        RewardsView.this.fireCommonEvent("browserCouldNotBeOpened", new Object[0]);
      }
    });
  }

  @JavascriptInterface
  public void pause()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 102	com/burstly/lib/component/networkcomponent/burstly/html/rewards/RewardsView:mUiHandler	Landroid/os/Handler;
    //   4: new 651	com/burstly/lib/component/networkcomponent/burstly/html/rewards/RewardsView$18
    //   7: dup
    //   8: aload_0
    //   9: aload_0
    //   10: invokespecial 652	com/burstly/lib/component/networkcomponent/burstly/html/rewards/RewardsView$18:<init>	(Lcom/burstly/lib/component/networkcomponent/burstly/html/rewards/RewardsView;Lcom/burstly/lib/component/networkcomponent/burstly/html/IDestroyableActivityLifecycleAware;)V
    //   13: invokevirtual 345	android/os/Handler:post	(Ljava/lang/Runnable;)Z
    //   16: pop
    //   17: return
  }

  public void paused()
  {
    fireVideoEvent("paused", new Object[0]);
  }

  @JavascriptInterface
  public void play()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 102	com/burstly/lib/component/networkcomponent/burstly/html/rewards/RewardsView:mUiHandler	Landroid/os/Handler;
    //   4: new 657	com/burstly/lib/component/networkcomponent/burstly/html/rewards/RewardsView$17
    //   7: dup
    //   8: aload_0
    //   9: aload_0
    //   10: invokespecial 658	com/burstly/lib/component/networkcomponent/burstly/html/rewards/RewardsView$17:<init>	(Lcom/burstly/lib/component/networkcomponent/burstly/html/rewards/RewardsView;Lcom/burstly/lib/component/networkcomponent/burstly/html/IDestroyableActivityLifecycleAware;)V
    //   13: invokevirtual 345	android/os/Handler:post	(Ljava/lang/Runnable;)Z
    //   16: pop
    //   17: return
  }

  @JavascriptInterface
  public void playVideo(final String paramString)
  {
    this.mUiHandler.post(new SafeRunnable(this)
    {
      public void doRun()
      {
        LoggerExt localLoggerExt = RewardsView.LOG;
        Object[] arrayOfObject = new Object[1];
        arrayOfObject[0] = paramString;
        localLoggerExt.logDebug("RewardsView", "Executing 'playVideo' {0}", arrayOfObject);
        if ((RewardsView.this.mContentParent != null) && (RewardsView.this.mVideoView == null) && (RewardsView.this.mModalView == null) && (RewardsView.this.mMraidViewContainer == null))
        {
          Context localContext = RewardsView.this.getContext();
          RewardsView.this.mVideoViewContainer = new CloseableContainer(localContext);
          RewardsView.this.mVideoView = new RewardsVideoView(localContext);
          RewardsView.this.mVideoViewContainer.putIntoContainer(RewardsView.this.mVideoView);
          RewardsView.this.mVideoViewContainer.setCloseClickListener(RewardsView.this);
          RewardsView.this.mVideoViewContainer.setShowCloseButtonDelay(3000L);
          RewardsView.this.mVideoView.setVideoEventsListener(RewardsView.this);
          int i = Utils.getFillparentValue();
          RewardsView.this.mVideoView.setLayoutParams(new FrameLayout.LayoutParams(i, i));
          RewardsView.this.mContentParent.addView(RewardsView.this.mVideoViewContainer);
          RewardsView.this.mVideoView.playVideo(paramString);
          RewardsView.this.fireCommonEvent("videoOpened", new Object[0]);
          return;
        }
        RewardsView.this.fireVideoEvent("couldNotPlayVideo", new Object[0]);
      }
    });
  }

  @JavascriptInterface
  public void precacheVideo(String paramString)
  {
    LOG.logDebug("RewardsView", "Executing 'precacheVideo' {0}", new Object[] { paramString });
    this.mVideoCache = VideoCache.getInstance(getContext());
    this.mVideoCache.setCacheListener(this);
    this.mVideoCache.cacheVideo(paramString);
  }

  void publishBridgeLoaded()
  {
    if ((this.mPageLoaded) && (!this.mPublishedBridgeLoaded) && (isShown()))
    {
      executeScriptUnSafe("console.log(\"firing window.burstlyBridgeLoaded if defined\"); if (window.burstlyBridgeLoaded != null) window.burstlyBridgeLoaded();");
      this.mPublishedBridgeLoaded = true;
    }
  }

  @JavascriptInterface
  public void setBackgroundColor(String paramString)
  {
    Integer localInteger = Utils.getColorFromHex(paramString);
    if (localInteger != null)
    {
      LOG.logDebug("RewardsView", "Setting {0} background color to Rewards view", new Object[] { paramString });
      setBackgroundColor(localInteger.intValue());
      return;
    }
    LOG.logWarning("RewardsView", "Can not parse {0} background color", new Object[] { paramString });
  }

  public void setCloseButtonControl(ICloseControl paramICloseControl)
  {
    this.mCloseButtonControl = paramICloseControl;
  }

  @JavascriptInterface
  public void setCurrentTime(final int paramInt)
  {
    this.mUiHandler.post(new VideoRunnable(this, paramInt)
    {
      public void doVideoRun()
      {
        LoggerExt localLoggerExt = RewardsView.LOG;
        Object[] arrayOfObject1 = new Object[1];
        arrayOfObject1[0] = Integer.valueOf(paramInt);
        localLoggerExt.logDebug("RewardsView", "Executing 'setCurrentTime' {0}", arrayOfObject1);
        VideoView localVideoView = RewardsView.this.mVideoView.getVideoView();
        if ((paramInt >= 0) && (paramInt <= localVideoView.getDuration()))
        {
          localVideoView.seekTo(paramInt);
          RewardsView localRewardsView = RewardsView.this;
          Object[] arrayOfObject2 = new Object[1];
          arrayOfObject2[0] = Integer.valueOf(paramInt);
          localRewardsView.fireVideoEvent("timeUpdate", arrayOfObject2);
          return;
        }
        RewardsView.this.fireVideoEvent("couldNotSetTime", new Object[0]);
      }
    });
  }

  public void setHostingOverlay(OverlayContainer<?> paramOverlayContainer)
  {
    super.setHostingOverlay(paramOverlayContainer);
    if (paramOverlayContainer != null)
    {
      this.mContentParent = paramOverlayContainer.getContainerLayout();
      return;
    }
    this.mContentParent = ((ViewGroup)((Activity)getContext()).getWindow().getDecorView());
  }

  @JavascriptInterface
  @TargetApi(9)
  public void setOrientations(int paramInt)
  {
    LoggerExt localLoggerExt1 = LOG;
    Object[] arrayOfObject1 = new Object[1];
    arrayOfObject1[0] = Integer.valueOf(paramInt);
    localLoggerExt1.logDebug("RewardsView", "Executing 'setOrientations' {0}", arrayOfObject1);
    int i = -1;
    switch (paramInt)
    {
    case 3:
    case 5:
    case 6:
    case 7:
    default:
      LoggerExt localLoggerExt2 = LOG;
      Object[] arrayOfObject2 = new Object[1];
      arrayOfObject2[0] = Integer.valueOf(paramInt);
      localLoggerExt2.logDebug("RewardsView", "Unsupported orientation: {0}", arrayOfObject2);
    case 4:
    case 8:
    case 1:
      while (true)
      {
        if (i != -1)
        {
          final int j = i;
          this.mUiHandler.post(new SafeRunnable(this)
          {
            public void doRun()
            {
              Context localContext = RewardsView.this.getContext();
              if ((localContext instanceof Activity))
                ((Activity)localContext).setRequestedOrientation(j);
            }
          });
        }
        return;
        if (supportReverseLayout());
        for (i = 9; ; i = 1)
          break;
        i = 0;
        continue;
        i = 1;
      }
    case 2:
    }
    if (supportReverseLayout());
    for (i = 8; ; i = 0)
      break;
  }

  public void setParentRewardsView(RewardsView paramRewardsView)
  {
    this.mParentRewardsView = paramRewardsView;
  }

  public void setWebChromeClient(WebChromeClient paramWebChromeClient)
  {
    super.setWebChromeClient(new ChromeClientWrapper(paramWebChromeClient)
    {
      public void onConsoleMessage(String paramAnonymousString1, int paramAnonymousInt, String paramAnonymousString2)
      {
        LoggerExt localLoggerExt = RewardsView.LOG;
        Object[] arrayOfObject = new Object[2];
        arrayOfObject[0] = paramAnonymousString1;
        arrayOfObject[1] = Integer.valueOf(paramAnonymousInt);
        localLoggerExt.logDebug("RewardsView", "console.log({0}, line {1})", arrayOfObject);
        super.onConsoleMessage(paramAnonymousString1, paramAnonymousInt, paramAnonymousString2);
      }

      public boolean onJsAlert(WebView paramAnonymousWebView, String paramAnonymousString1, String paramAnonymousString2, JsResult paramAnonymousJsResult)
      {
        RewardsView.this.dispatchAction(paramAnonymousString2);
        super.onJsAlert(paramAnonymousWebView, paramAnonymousString1, paramAnonymousString2, paramAnonymousJsResult);
        paramAnonymousJsResult.confirm();
        return true;
      }
    });
  }

  public void setWebViewClient(WebViewClient paramWebViewClient)
  {
    super.setWebViewClient(new WebViewClientWrapper(paramWebViewClient)
    {
      public void onLoadResource(WebView paramAnonymousWebView, String paramAnonymousString)
      {
        RewardsView.LOG.logDebug("RewardsView", "Loading {0}", new Object[] { paramAnonymousString });
        super.onLoadResource(paramAnonymousWebView, paramAnonymousString);
      }

      public void onPageFinished(WebView paramAnonymousWebView, String paramAnonymousString)
      {
        super.onPageFinished(paramAnonymousWebView, paramAnonymousString);
        paramAnonymousWebView.loadUrl("javascript:function burstly_videoPlay() {alert(\"pVideo=\"+ findVideoSrc()); return false; }");
        paramAnonymousWebView.loadUrl("javascript:function burstly_dispatchPlay() { var burstly_evt = document.createEvent('Event'); burstly_evt.initEvent('play', true, true); return document.getElementById(burstly_videoElement).dispatchEvent(burstly_evt); }");
        paramAnonymousWebView.loadUrl("javascript:function burstly_dispatchTimeupdate() { var burstly_evt = document.createEvent('Event'); burstly_evt.initEvent('timeupdate', true, true); return document.getElementById(burstly_videoElement).dispatchEvent(burstly_evt); }");
        paramAnonymousWebView.loadUrl("javascript:function burstly_dispatchEnded() { var burstly_evt = document.createEvent('Event'); burstly_evt.initEvent('ended', true, true); return document.getElementById(burstly_videoElement).dispatchEvent(burstly_evt); }");
        RewardsView.this.updateDataObject(0, 0);
        paramAnonymousWebView.loadUrl("javascript:function burstly_videoDuration() { return burstly_videoDummy.duration; }");
        paramAnonymousWebView.loadUrl("javascript:function burstly_videoCurrentTime() { return burstly_videoDummy.currentTime; }");
        paramAnonymousWebView.loadUrl("javascript:function findVideoSrc() {var burstly_videoElementObject = document.getElementById(burstly_videoElement);if (burstly_videoElementObject) {var content = burstly_videoElementObject.innerHTML,srcs = content.match(/src=(.+\")/);if (srcs == null || srcs.length < 2) {return burstly_videoElementObject.src;}return srcs[1]; }}");
        paramAnonymousWebView.loadUrl("javascript:var burstly = window.burstly || { rewards: {getVersion : function() { return '0.1'; }} }; if (!burstly.rewards){ burstly.rewards = {getVersion : function() { return '0.1'; }}};window.burstly = burstly;");
        RewardsView.this.mPageLoaded = true;
        RewardsView.this.publishBridgeLoaded();
        RewardsView.this.fireBridgeStateEvent(RewardsView.getState(RewardsView.this.isShown()), false);
      }

      public void onPageStarted(WebView paramAnonymousWebView, String paramAnonymousString, Bitmap paramAnonymousBitmap)
      {
        super.onPageStarted(paramAnonymousWebView, paramAnonymousString, paramAnonymousBitmap);
        RewardsView.this.mPageLoaded = false;
        RewardsView.this.mPublishedBridgeLoaded = false;
      }

      public boolean shouldOverrideUrlLoading(WebView paramAnonymousWebView, String paramAnonymousString)
      {
        if (!super.shouldOverrideUrlLoading(paramAnonymousWebView, paramAnonymousString))
        {
          if (paramAnonymousString.toLowerCase().startsWith("http"))
          {
            RewardsView.LOG.logInfo("RewardsView", "Url to open in current window {0}", new Object[] { paramAnonymousString });
            paramAnonymousWebView.loadUrl(paramAnonymousString);
          }
        }
        else
          return true;
        try
        {
          RewardsView.LOG.logInfo("RewardsView", "Url to open in new window {0}", new Object[] { paramAnonymousString });
          Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse(paramAnonymousString));
          RewardsView.this.getContext().startActivity(localIntent);
          return true;
        }
        catch (ActivityNotFoundException localActivityNotFoundException)
        {
          RewardsView.LOG.logError("RewardsView", localActivityNotFoundException.getMessage(), new Object[0]);
        }
        return true;
      }
    });
  }

  @JavascriptInterface
  public void showNativeControls()
  {
    final ICloseControl localICloseControl = this.mCloseButtonControl;
    if (localICloseControl != null)
    {
      this.mUiHandler.post(new SafeRunnable(this)
      {
        public void doRun()
        {
          RewardsView.LOG.logDebug("RewardsView", "Executing 'showNativeControls'", new Object[0]);
          localICloseControl.showClose(true);
        }
      });
      return;
    }
    LOG.logWarning("RewardsView", "Can not send 'show native control' event. Native control listener is null", new Object[0]);
  }

  @JavascriptInterface
  public void showVideoControls()
  {
    final RewardsVideoView localRewardsVideoView = this.mVideoView;
    if (localRewardsVideoView != null)
      this.mUiHandler.post(new SafeRunnable(this)
      {
        public void doRun()
        {
          RewardsView.LOG.logDebug("RewardsView", "Executing 'showVideoControls'", new Object[0]);
          localRewardsVideoView.getController().setVisibility(0);
        }
      });
  }

  public void started()
  {
    fireVideoEvent("started", new Object[0]);
  }

  @JavascriptInterface
  public void stop()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 102	com/burstly/lib/component/networkcomponent/burstly/html/rewards/RewardsView:mUiHandler	Landroid/os/Handler;
    //   4: new 750	com/burstly/lib/component/networkcomponent/burstly/html/rewards/RewardsView$19
    //   7: dup
    //   8: aload_0
    //   9: aload_0
    //   10: invokespecial 751	com/burstly/lib/component/networkcomponent/burstly/html/rewards/RewardsView$19:<init>	(Lcom/burstly/lib/component/networkcomponent/burstly/html/rewards/RewardsView;Lcom/burstly/lib/component/networkcomponent/burstly/html/IDestroyableActivityLifecycleAware;)V
    //   13: invokevirtual 345	android/os/Handler:post	(Ljava/lang/Runnable;)Z
    //   16: pop
    //   17: return
  }

  public void timeUpdate(int paramInt)
  {
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = Integer.valueOf(paramInt);
    fireVideoEvent("timeUpdate", arrayOfObject);
  }

  public void unpaused()
  {
    fireVideoEvent("unpaused", new Object[0]);
  }

  void updateDataObject(int paramInt1, int paramInt2)
  {
    loadUrl("javascript:var burstly_videoDummy = { \"duration\" : " + paramInt1 + ", \"currentTime\" : " + paramInt2 + "};");
  }

  @JavascriptInterface
  public String url()
  {
    LOG.logDebug("RewardsView", "Executing 'url'", new Object[0]);
    if (this.mVideoView == null)
      return "none";
    return this.mVideoView.getOriginalVideoUrl();
  }

  private abstract class VideoRunnable extends SafeRunnable
  {
    protected VideoRunnable(IDestroyableActivityLifecycleAware arg2)
    {
      super();
    }

    public final void doRun()
    {
      if ((RewardsView.this.mVideoView != null) && (RewardsView.this.mVideoView.isPrepared()))
      {
        doVideoRun();
        return;
      }
      RewardsView.this.fireVideoEvent("videoNotLoaded", new Object[0]);
    }

    abstract void doVideoRun();
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.html.rewards.RewardsView
 * JD-Core Version:    0.6.2
 */